﻿' LibWowArmory
' by Ronald M. Clifford (roncli@roncli.com)
'
' This source code is released under the GNU Library General Public License (LGPL) Version 2.1.

Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Web
Imports System.Xml.Serialization

Namespace roncliProductions.LibWowArmory

    ''' <summary>
    ''' A class that caches additional data for the dungons and bosses available on the Armory
    ''' </summary>
    ''' <remarks>This class is largely used for internal purposes</remarks>
    Public Class DungeonData
        Inherits WowArmoryData

        Private ddsDungeons As New DungeonDataSchema.dungeons

        ''' <summary>
        ''' Returns a list of available dungeons
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Dungeons() As List(Of Dungeon)
            Get
                If ddsDungeons Is Nothing Then
                    Return New List(Of Dungeon)
                End If
                Return (From a In ddsDungeons.dungeon Select New Dungeon(CBool(a.hasHeroic), a.nameId)).ToList()
            End Get
        End Property

        ''' <summary>
        ''' The URL of the dungeon and boss data
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Overrides ReadOnly Property URL() As String
            Get
                Return "http://www.wowarmory.com/data/dungeons.xml"
            End Get
        End Property

        ''' <summary>
        ''' Indicates to the inherited class that this request does not require login
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Overrides ReadOnly Property RequiresLogin() As Boolean
            Get
                Return False
            End Get
        End Property

        ''' <summary>
        ''' Constructor that retrieves the dungeon and boss data from either the armory or the local cache
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New()
            If Cache.Cache("LibWowArmory.DungeonData") Is Nothing Then
                MyBase.Retrieve()

                Dim xsSerializer As New XmlSerializer(ddsDungeons.GetType())

                Dim srXML As New StringReader(MyBase.strData)

                ddsDungeons = CType(xsSerializer.Deserialize(srXML), DungeonDataSchema.dungeons)

                Cache.Cache.Insert("LibWowArmory.DungeonData", ddsDungeons, Nothing, Date.UtcNow.AddDays(1), Nothing, Caching.CacheItemPriority.NotRemovable, Nothing)
            Else
                ddsDungeons = CType(Cache.Cache("LibWowArmory.DungeonData"), DungeonDataSchema.dungeons)
            End If
        End Sub

        ''' <summary>
        ''' A class that encapsulates a single dungeon returned from the Armory
        ''' </summary>
        ''' <remarks></remarks>
        Public Class Dungeon

            Private blnHasHeroic As Boolean
            Private intID As Integer

            ''' <summary>
            ''' Determines whether or not this dungeon has an heroic version
            ''' </summary>
            ''' <value></value>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Property HasHeroic() As Boolean
                Get
                    Return blnHasHeroic
                End Get
                Set(ByVal value As Boolean)
                    blnHasHeroic = value
                End Set
            End Property

            ''' <summary>
            ''' The dungeon's identification number
            ''' </summary>
            ''' <value></value>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Property ID() As Integer
                Get
                    Return intID
                End Get
                Set(ByVal value As Integer)
                    intID = value
                End Set
            End Property

            ''' <summary>
            ''' Constructor to create a new dungeon object
            ''' </summary>
            ''' <param name="blnHasHeroic"></param>
            ''' <param name="intID"></param>
            ''' <remarks></remarks>
            Friend Sub New(ByVal blnHasHeroic As Boolean, ByVal intID As Integer)
                Me.blnHasHeroic = blnHasHeroic
                Me.intID = intID
            End Sub

        End Class

    End Class

End Namespace